<HTML><HEAD><TITLE>tent_minimize_random(+MoveGenerator, ?Violations, -MoveId)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">library(tentative)</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>tent_minimize_random(+MoveGenerator, ?Violations, -MoveId)</H1>
Find a move that minimizes violations
<DL>
<DT><EM>MoveGenerator</EM></DT>
<DD>A goal
</DD>
<DT><EM>Violations</EM></DT>
<DD>A tentative variable
</DD>
<DT><EM>MoveId</EM></DT>
<DD>Placeholder for move identifier
</DD>
</DL>
<H2>Description</H2>

	This metapredicate finds a local search move that minimizes
	violations. It requries that the tentative variables and constraints
	over them have been set up beforehand. 
	<P>
    	MoveGenerator is a nondeterministic goal that implements a local
	search step. It should explore all neighbours on backtracking.
	A move should be made by changing tentative values, and
	instantiating MoveId to a unique identifier for every move.
	<P>
	Violations should be a tentative variable that reflects the
	total problem violations that are to be minimized.
	<P>
	MoveId is a variable which occurs in MoveGenerator. At the end of
	minimization, it will contain the ID of the best move. If there
	are multiple moves of the same quality, a random one is returned.
	<P>
	After tent_minimize_random/3 succeeds, all the trial moves are undone
	and the computation state is as before the call. Only the MoveId
	contains the identifier of the best move. This move can then be
	committed to by performing it again according to MoveId.
    
<H3>Modules</H3>
This predicate is sensitive to its module context (tool predicate, see @/2).
<H3>Fail Conditions</H3>
Fails if MoveGenerator fails
<H2>Examples</H2>
<PRE>

    % This example tries 8 moves that lead to different tentative values
    % of Viol. One of the moves that lead to a value of 1 is selected.

    ?-  Viol tent_set 0,
	tent_minimize_random((
		between(1, 8, 1, MoveId),
		arg(MoveId, viol(9,5,6,1,3,6,1,9), N),
		Viol tent_set N
	    ), Viol, MoveId).
     ...
     MoveId = 7		% 4 or 7, the result is random!
     Yes (0.00s cpu)
    </PRE>
<H2>See Also</H2>
<A HREF="../../lib/tentative/tent_set-2.html">tent_set / 2</A>
</BODY></HTML>
